package displayboardinfo.tests;

import java.net.URI;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;

import displayboardinfo.entities.Patient;
import displayboardinfo.entities.Room;
import displayboardinfo.entities.User;
import displayboardinfo.messages.ListPatientsRes;
import displayboardinfo.utils.Utils;

public class ServicesTest {
	public static void main(String[] args) throws ParseException {
		ClientConfig config = new DefaultClientConfig();
		Client client = Client.create(config);
		WebResource service = client.resource(getBaseURI());

		Patient pat = new Patient();
//		pat.setId(new Long(1));
		pat.setPesel("12345678915");
		pat.setName("ktos");
		pat.setSurname("Jakis2");

//		User user = new User();
//		user.setId(new Long(2));
//		user.setLogin("rejestracja");
//		
//		user.setPassword(Utils.convertToSHA1("password"));
//		
//		user.setName("Janina");
//		user.setSurname("Kopara");
//		user.setUserType("r");
//		
//		ArrayList<Room> rooms = new ArrayList<Room>();
//		rooms.add(new Room(new Long(1)));
//		
//		user.setRooms(rooms);
		
		try{
			ClientResponse resp = service.path("patients").path("add").type(MediaType.APPLICATION_XML).post(ClientResponse.class, pat);
	
			if (resp.getStatus() == ClientResponse.Status.NOT_ACCEPTABLE.getStatusCode()){
				System.err.println("Not acceptable");
				System.err.println(resp.getEntity(String.class));
			}
			else {
				System.out.println(resp);
				Patient patient = resp.getEntity(Patient.class);
				System.out.println("ID: " + patient.getId());
			}
			
		} catch (Exception e){
			System.err.println("Exception");
		}
		
	}

	private static URI getBaseURI() {
		return UriBuilder.fromUri(
				"http://localhost:8080/DisplayBoardInfoServer").build();
	}
}
